﻿using System;

namespace yacomp.helpers
{
    internal partial class helper
    {
        internal const ushort msdos_fastyear = 1980;
        public static ushort read_msdos_time(DateTime time)
        {
            return (ushort)((time.Hour<<11) | (time.Minute <<5) |(time.Second/2));
        }
        public static ushort read_msdos_date(DateTime time)
        {
            return (ushort)(((time.Year- msdos_fastyear) <<9) | (time.Month <<5) | (time.Day));
        }
        public static DateTime read_datetime_by_msdos(ushort time, ushort date)
        {
            if (time == 0 && date == 0) return DateTime.Now;
            return new DateTime(msdos_fastyear + (date >> 9), (date >> 5) & 0b1111, date & 0b11111, time >> 11, (time >> 5) & 0b111111, (time & 0b11111)*2);
        }
    }
}
